<template>
  <div class="dashboard-container">
    <div class="app-container">
      <el-card>
        <PageTool :show-before="true">
          <template v-slot:after>
            <el-button
              class="button"
              type="primary"
              size="small"
              @click="add"
            >添加角色</el-button>
          </template>
        </PageTool>
        <template>
          <!-- 表格 -->
          <el-table
            :data="tableData"
            border
            style="width: 100%;border:none"
          >
            <el-table-column class="title" prop="title" label="角色名称" width="400" />
            <el-table-column prop="description" label="角色描述" width="500" />
            <el-table-column label="操作" width="500">
              <template v-slot="{row}">
                <el-button type="primary" size="small" @click="ad(row.id)">分配权限</el-button>
                <el-button size="small" @click="edit(row.id)">编辑</el-button>
                <el-button type="danger" size="small" @click="del(row.id)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </template>
      </el-card>
      <!-- 添加角色 -->
      <AddRole ref="addRole" :show-dialog.sync="visibleDialog" @updateEvent="getRoleList" />
      <permis ref="AssignPerm" :show-dialog.sync="showDialog" />
    </div>
  </div>
</template>
<script>
import { getRoleList, delRole } from '@/api/model/role.js'
import AddRole from './components/AddRole.vue'
import permis from './components/permis.vue'
export default {
  components: { AddRole, permis },
  data() {
    return {
      tableData: [

      ],
      visibleDialog: false, // 添加权限
      showDialog: false // 分配权限
    }
  },
  created() {
    this.getRoleList()
  },
  methods: {
    // 添加权限
    ad(id) {
      // console.log(61)
      this.showDialog = true
      this.$refs.AssignPerm.getAssignRole(id)
    },
    // 编辑角色
    edit(id) {
      this.visibleDialog = true
      this.$refs.addRole.getAssignRole(id)
    },
    // 删除角色
    del(id) {
      this.$confirm('是否确定删除?', '提示', {
        type: 'warning'
      }).then(async() => {
        await delRole(id)
        // 更新
        this.getRoleList()
      })
    },
    // 新增
    add() {
      this.visibleDialog = true
    },
    // 获取列表
    async getRoleList() {
      const res = await getRoleList({
        _limit: 5,
        _start: 0
      })
      console.log('111111', res)
      this.tableData = res.data
    }
  }
}
</script>
<style scoped>
.search {
  margin-top: 15px;
}

::v-deep .el-table_1_column_1 {
  height: 100px;
}

.button {
  margin-left: 700px;
}

::v-deep .el-table td {
  height: 0;
}

::v-deep .el-table th {
  height: 0;
}
</style>

